package map.animation
{
	public class AnimationManager
	{
		private var _animations:Vector.<BaseMapAnimation>;
		private var _currentAnimation:BaseMapAnimation;
		public function AnimationManager()
		{
			_animations = new Vector.<BaseMapAnimation>();
		}
		
		public function addAnimation(animation:BaseMapAnimation):void
		{
			if(_currentAnimation && _currentAnimation.isSame(animation))
			{
				if(_currentAnimation.priority <= animation.priority)
				{
					_currentAnimation.cancle();
					_currentAnimation = null;
					_animations.push(animation);
				}
			}else{
				_animations.push(animation);
			}
		}
		
		public function update():void
		{
			if(_currentAnimation && !_currentAnimation.finished)
			{
				_currentAnimation.updata();
			}else{
				if(_animations.length > 0)
				{
					_currentAnimation = _animations.shift();
					_currentAnimation.prepare();
				}else
				{
					_currentAnimation = null;
				}
			}
		}
	}
}